<?php

class Core_Table_Design_Block extends Kd_Data_Table {

    public function __construct() {
        parent::__construct();
    }

    public function getMaxSorting($templateId, $position){
        return Kd_Data_Factory::getQueryDcl()
                    ->from($this->getName())
                    ->field(Kd_Data_Dcl_Fn::max('sorting'), 'max_position')
                    ->eq('page_template_id', ':pageTemplate:s')
                    ->eq('position', ':position:s')
                    ->addParameter('pageTemplate', $templateId)
                    ->addParameter('position', $position)
                    ->fetch()
                    ->getFirstValue();
    }

    public function updateSorting($id, $position) {
        Kd_Data_Factory::getUpdateDcl()
                ->into($this->getName())
                ->value('sorting', $position)
                ->eq('id', ':id:s')
                ->addParameter('id', $id)
                ->execute();
    }

}

